package com.drunkoid.server;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UpdateLoctionServlet  extends HttpServlet{

	/**
	 * The client will send his location to this servlet
	 */
	private static final long serialVersionUID = -1296535060478193411L;
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
		    String id = request.getParameter("id");
		    double longitude = Double.parseDouble(request.getParameter("longitude"));
		    double latitude = Double.parseDouble(request.getParameter("latitude"));
		  
			ServerMgr manager = ServerMgr.getInstance();
			int result = manager.updateLocation(id, longitude, latitude);	
			response.getWriter().print("result= "+result);
			OutputStream outstr = response.getOutputStream();
			ObjectOutputStream oos = new  ObjectOutputStream(outstr);
			oos.writeObject(result);
			oos.flush();
			oos.close();
		} catch (Exception e) { 
			e.printStackTrace();
		}		
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
